<?php 
mn_field('hidden','ED','Delete','','','','','');
	$SUMSERIALS = 0;
	$RESULT = 0;
		for ($n = 0; $n < $_POST['AritmContr']; $n++) {

			$QUAN = 'QUANT'.($n+1);
			$VALU = 'VALUE'.($n+1);
			$RESULT = $RESULT+$_POST[$QUAN]*$_POST[$VALU];
		}
	$_POST['SUMValues'] = $RESULT;

	echo '<script charset="utf-8" type="text/javascript">document.InvoiceProperties.ctr_RegAmount.value=\''.$RESULT.'\';</script>';
if (isset($_POST['Delete']) && $_POST['Delete'] > 0) {
			$GLOBALS['MYT']->db_query("UPDATE cur_serials SET Status = 5 WHERE ref = {$_POST['Delete']}");
	}
if (isset($_POST['Serial']) && isset($_POST['Insert'])) {

	if (strlen($_POST['Serial']) >= 9) {

	$GLOBALS['MYT']->db_query("INSERT INTO cur_serials (refCurrency,
												Amount,
												Serial,
												Time,
												refOperator,
												refOwner,
												refOperation,
												Status)
										VALUES ({$_POST['IN']},
												'{$_POST['AddAmount']}',
												'{$_POST['Serial']}',
												'{$sysTime}',
												{$_SESSION[$SESSID]},
												{$_POST['OBJCTCL']},
												{$_POST['TmpOp']},
												1)");
	$GLOBALS['MYT']->db_query("UPDATE exchange_tmpops SET Status = 6
										WHERE ref = {$_POST['TmpOp']}");
	}
}
echo '<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">';
$Serials = $GLOBALS['MYT']->db_array("SELECT * FROM cur_serials WHERE refOperation = {$_POST['TmpOp']} AND Status != 5 ORDER BY ref ASC");
	for ($r = 1; $r <= $Serials[0]; $r++) {
		$SUMSERIALS = $SUMSERIALS+$Serials[$r]['Amount'];

			echo '<tr><td bgcolor="#E2E2E2">Valor: '.$Serials[$r]['Amount'];
			$C = "SELECT miso_Cod_elite AS ID, miso_ID AS NAME FROM hd_monedasiso WHERE miso_Cod_elite = {$_POST['FraCalcISO']}";
			mn_field('select','RD','','',$C,'','False','');
			echo'</td><td>Serie: '.strtoupper($Serials[$r]['Serial']).'</td>'; ?>
			<td>
			<?php mn_field('button','ED','','','','','','delbutton" alt="Eliminar"
			onclick="document.InvoiceProperties.Delete.value='.$Serials[$r]['ref'].';
			document.InvoiceProperties.action=\''.$MODURL.'exe_inv/exe_registred.mex\';
			subform(\'InvoiceProperties\',\'Exc_registred\');'); ?></td></tr>
			<?php
	} ?>
<?php
	$Serials = $GLOBALS['MYT']->db_array("SELECT SUM(Amount) AS Amount, refCurrency FROM cur_serials WHERE refOperation = {$_POST['TmpOp']} AND Status != 5 GROUP BY refCurrency");?>
          <tr>
            <td bgcolor="#E2E2E2" colspan="3">Valor:
	<?php
	$Qur = "SELECT cur_values.VALUE AS ID, cur_values.VALUE AS NAME FROM hd_monedasiso
	  							INNER JOIN cur_checks ON cur_checks.CURRENCY = miso_Cod_elite
								INNER JOIN cur_values ON cur_checks.CURRENCY_ISO = cur_values.CURRENCY
								WHERE miso_Cod_elite = {$_POST['FraCalcISO']}
								AND STATUS = 1
								AND COMP_SERVICE = 1
								AND cur_values.REF > cur_checks.VALUE";
	mn_field('select','ED','AddAmount','',$Qur,'','','');
	$C = "SELECT miso_Cod_elite AS ID, miso_ID AS NAME FROM hd_monedasiso WHERE miso_Cod_elite = {$_POST['FraCalcISO']}";
	mn_field('select','ED','IN','',$C,'','False',''); ?>
              Serie:
			  <?php
			  mn_field('text','ED','Serial','','11','11','','');
			  mn_field('button','ED','Insert','Registar','','','','"
			  onclick="document.InvoiceProperties.action=\''.$MODURL.'exe_inv/exe_registred.mex\';
			  subform(\'InvoiceProperties\',\'Exc_registred\');'); ?>
            </td>
          </tr>
       <tr>
            <td bgcolor="#E2E2E2" colspan="3">
	<?php

	$C = "SELECT miso_Cod_elite AS ID, miso_ID AS NAME FROM hd_monedasiso WHERE miso_Cod_elite = {$_POST['FraCalcISO']}";
	mn_field('select','RD','','',$C,'','False','');
	$SUMSERIALS = $_POST['SUMValues']+$SUMSERIALS;
	echo '<script charset="utf-8" type="text/javascript">
		document.InvoiceProperties.FraCalc.value=\''.round($SUMSERIALS,2).'\';
		document.InvoiceProperties.ctr_RegAmount.value=\''.round($SUMSERIALS,2).'\';</script>';
	?></td>
          </tr>
</table>